package de.nroz.view;

import java.awt.Color;
import java.awt.Component;
import java.util.prefs.BackingStoreException;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

import de.nroz.model.Images;

public class BooleanCellRenderer extends DefaultTableCellRenderer
{

	/**
	 * 
	 */
	private static final long serialVersionUID = -500278743772084378L;
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column)
	{
		if(isSelected)
		{
			setBackground(Images.LIGHT_GRAY);
		}
		else
		{
			setBackground(Color.WHITE);
		}
		if(value instanceof Boolean)
		{
			setValue(null);
			if((Boolean)value == Boolean.TRUE)
			{
				setIcon(Images.ledgreen);
			}
			else
			{
				setIcon(Images.ledred);
			}
			setHorizontalAlignment(SwingConstants.CENTER);
		}
		
		return this;
	}
}
